package com.ruoyi.biz.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.biz.domain.TrafficRecord;
import com.ruoyi.biz.service.ITrafficRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 通行记录Controller
 *
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/biz/trafficRecord")
public class TrafficRecordController extends BaseController {
	@Autowired
	private ITrafficRecordService trafficRecordService;

	/**
	 * 查询通行记录列表
	 */
	@PreAuthorize("@ss.hasPermi('biz:trafficRecord:list')")
	@GetMapping("/list")
	public TableDataInfo list(TrafficRecord trafficRecord) {
		startPage();
		List<TrafficRecord> list = trafficRecordService.selectTrafficRecordList(trafficRecord);
		return getDataTable(list);
	}

	/**
	 * 导出通行记录列表
	 */
	@PreAuthorize("@ss.hasPermi('biz:trafficRecord:export')")
	@Log(title = "通行记录", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, TrafficRecord trafficRecord) {
		List<TrafficRecord> list = trafficRecordService.selectTrafficRecordList(trafficRecord);
		ExcelUtil<TrafficRecord> util = new ExcelUtil<TrafficRecord>(TrafficRecord.class);
		util.exportExcel(response, list, "通行记录数据");
	}
	@PreAuthorize("@ss.hasPermi('biz:trafficRecord:import')")
	@Log(title = "通行记录", businessType = BusinessType.IMPORT)
	@PostMapping("/importData")
	public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
		ExcelUtil<TrafficRecord> util = new ExcelUtil<TrafficRecord>(TrafficRecord.class);
		List<TrafficRecord> list = util.importExcel(file.getInputStream());
		trafficRecordService.saveBatch(list);
		return AjaxResult.success();
	}

	/**
	 * 获取通行记录详细信息
	 */
	@PreAuthorize("@ss.hasPermi('biz:trafficRecord:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return success(trafficRecordService.selectTrafficRecordById(id));
	}

	/**
	 * 新增通行记录
	 */
	@PreAuthorize("@ss.hasPermi('biz:trafficRecord:add')")
	@Log(title = "通行记录", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody TrafficRecord trafficRecord) {
		return toAjax(trafficRecordService.insertTrafficRecord(trafficRecord));
	}

	/**
	 * 修改通行记录
	 */
	@PreAuthorize("@ss.hasPermi('biz:trafficRecord:edit')")
	@Log(title = "通行记录", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody TrafficRecord trafficRecord) {
		return toAjax(trafficRecordService.updateTrafficRecord(trafficRecord));
	}

	/**
	 * 删除通行记录
	 */
	@PreAuthorize("@ss.hasPermi('biz:trafficRecord:remove')")
	@Log(title = "通行记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(trafficRecordService.deleteTrafficRecordByIds(ids));
	}
}
